/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.gui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author Ripper
 */
public class CommandlineScreen extends ServerPanel implements ActionListener
{
    private JTextArea textArea;
    private JTextField inputField;
    private JButton inputButton;
    
    public CommandlineScreen(ServerWindow parent)
    {
        super(parent);
        setLayout(new BorderLayout());
        
        textArea = new JTextArea();
        textArea.setEditable(false);
        JScrollPane scroller = new JScrollPane(textArea);
        add(scroller, BorderLayout.CENTER);
        
        JPanel bottomPanel = new JPanel(new BorderLayout());
        {
            inputField = new JTextField("");
            inputField.addActionListener(this);
            bottomPanel.add(inputField, BorderLayout.CENTER);
            
            inputButton = new JButton(" Submit ");
            inputButton.addActionListener(this);
            bottomPanel.add(inputButton, BorderLayout.EAST);
        }
        add(bottomPanel, BorderLayout.SOUTH);
    }
    
    public void logMessage(String msg)
    {
        textArea.append("\n"+msg);
    }

    @Override
    public void actionPerformed(ActionEvent e) 
    {
        if(e.getSource() == inputField || e.getSource() == inputButton)
        {
            getServerWindow().submitMessage(inputField.getText());
            inputField.setText("");
        }
    }
}
